<template>
  <div>
    <div class="product-content">
      <div class="upload-img" v-if="'undefined'==typeof(goodsID)">
        <div class="top-tips">
          <span class="text-l">上传图片</span>
          <span class="text-r">文件最大不能不超过*M，最多上传4张</span>
        </div>
        <div class="bottom-upload">
          <div class="same-box" v-for="(iu, index) in imgUrls" :key="iu.imageId">
            <img :src="iu">
            <span class="list-img-close" @click="delImage(index)"></span>
          </div>
          <div class="same-box" v-show="imgUrls.length<4">
            <input
              class="upload-img"
              id="inpupimg"
              type="file"
              @change="onFileChange"
              @click="tupxuanze(0,0)"
              accept="image/jpg, image/png, image/gif, image/jpeg, image/svg"
              multiple
            >
            <!--capture="camera"-->
            <label class="jia-icon" for="inpupimg"></label>
          </div>
        </div>
      </div>
      <div class="upload-img" v-else>
        <div class="top-tips">
          <span class="text-l">上传图片</span>
          <span class="text-r">文件最大不能不超过*M，最多上传4张</span>
        </div>
        <div class="bottom-upload">
          <div class="same-box" v-for="(iu, index) in albumsUrl" :key="iu.index">
            <img :src="iu.url">
            <span class="list-img-close" @click="delImagegod(iu.imageId)"></span>
          </div>
          <div class="same-box" v-show="albumsUrl.length<4">
            <input
              class="upload-img"
              id="inpupimg"
              type="file"
              @change="onFileChange"
              @click="tupxuanze(0,1)"
              accept="image/jpg, image/png, image/gif, image/jpeg, image/svg"
              multiple
            >
            <!--capture="camera"-->
            <label class="jia-icon" for="inpupimg"></label>
          </div>
        </div>
      </div>
      <ul class="release-list">
        <li class="list-li">
          <span class="left-text">设置产品封面</span>
          <div class="right-info xuanze-fo" @click="fengmian_show">
            <img :src="iu_url" class="fengmian">
            <i class="icon"></i>
          </div>
        </li>
        <!-- <router-link :to="{name:'Business_category_ad'}" class="href-icon">
            <li class="list-li list-li-zk" style="padding-left:11px;">
                <i class="l-icon l-icon4-1"></i>
                <span>添加产品类目</span>
                <span style="margin-left:83px; color:#999999;">未添加过产品类目请点击此处</span>
                <router-link :to="{name:'Business_category_ad'}" data-transition="slide" class="href-icon">
                    <i class="icon"></i>
                </router-link>
            </li>
        </router-link>-->
        <li class="list-li list-li-z" style="margin-top:10px;">
          <span class="left-text k">选择产品分类</span>
          <!-- <div @click="leimu()" class="right-info xuanze-fo">{{catname}}<i class="icon"></i></div> -->
          <div @click="showcates=true" class="right-info xuanze-fo">
            {{catname}}
            <i class="icon"></i>
          </div>
        </li>

        <li class="list-li">
          <span class="left-text">选择产品类型</span>
          <div class="shiwu">
            <span @click="ItemsChoose(0)" :class="{shiwuActive:ChooseStyle==0}"></span>
            实物
          </div>
          <div class="feishiwu">
            <span @click="ItemsChoose(1)" :class="{shiwuActive:ChooseStyle==1}"></span>
            非实物&nbsp;&nbsp;&nbsp;
          </div>
        </li>
        <li class="list-li" v-if="ChooseStyle==0">
          <span class="left-text">选择配送方式</span>
          <div class="shiwu">
            <span @click="logistics(1)" :class="{shiwuActive:logisticsStype==1}"></span>
            物流
          </div>
          <div class="feishiwu">
            <span @click="logistics(0)" :class="{shiwuActive:logisticsStype==0}"></span>
            自己配送
          </div>
        </li>
        <li class="list-li" v-if="ChooseStyle==1">
          <span class="left-text">设置使用时限</span>
          <input
            type="text"
            style="width:32%;font-size: 14px;"
            @click="openPicker"
            v-model="dataTimeqishi"
            readonly="readonly"
          >
          至
          <input
            type="text"
            style="width:32%;font-size: 14px;"
            placeholder="截止日期"
            @click="openPicker1"
            v-model="dataTimejieshu"
            readonly="readonly"
          >
        </li>
        <li class="list-li">
          <span class="left-text">产品标题：</span>
          <input type="text" v-model="goodsName" class="rt-input" placeholder="请填写产品标题">
        </li>
        <li class="list-li">
          <span class="left-text">产品价格：</span>
          <input type="number" v-model="goodsScreenPrice" class="rt-input" placeholder="请填写价格">
        </li>
        <li class="list-li">
          <span class="left-text">产品详情文字描述</span>
          <br>
        </li>
        <li style="background:#fff;">
          <textarea
            class="textlistLi"
            rows="3"
            cols="20"
            placeholder="添加商品描述不能超过(200字)"
            v-model="wenzishuoming"
          ></textarea>
        </li>
      </ul>
      <div class="upload-img" v-if="'undefined'==typeof(goodsID)">
        <div class="top-tips">
          <span class="text-l">上传产品详情图片</span>
          <span style="font-size: 0.5rem;">（建议800X800）</span>
        </div>
        <div class="bottom-upload bottom-upload2">
          <div
            class="same-box"
            style="width:20%;float:left;"
            v-for="(iu, index) in imgUrlsxp"
            :key="iu.index"
          >
            <img :src="iu">
            <span class="list-img-close" @click="delImagetp(index)"></span>
          </div>
          <div class="same-box" v-show="imgUrlsxp.length<5">
            <input
              class="upload-img"
              id="inpupimg"
              type="file"
              @change="onFileChange"
              @click="tupxuanze(1,0)"
              accept="image/jpg, image/png, image/gif, image/jpeg, image/svg"
              multiple
            >
            <!--capture="camera"-->
            <label class="jia-icon" for="inpupimg"></label>
          </div>
        </div>
      </div>
      <div class="upload-img" v-else>
        <div class="top-tips">
          <span class="text-l">上传产品详情图片</span>
          <span style="font-size: 0.5rem;">（建议800X800）</span>
        </div>
        <div class="bottom-upload bottom-upload2">
          <div
            class="same-box"
            style="width:20%;float:left;"
            v-for="(iu, index) in detailsAlbumsUrl"
            :key="iu.index"
          >
            <img :src="iu.url">
            <span class="list-img-close" @click="delImagegod(iu.imageId)"></span>
          </div>
          <div class="same-box" v-show="detailsAlbumsUrl.length<5">
            <input
              class="upload-img"
              id="inpupimg"
              type="file"
              @change="onFileChange"
              @click="tupxuanze(1,1)"
              accept="image/jpg, image/png, image/gif, image/jpeg, image/svg"
              multiple
            >
            <!--capture="camera"-->
            <label class="jia-icon" for="inpupimg"></label>
          </div>
        </div>
      </div>
      <ul class="release-list">
        <li class="list-li">
          <span class="left-text">选择产品类型</span>
          <div class="shiwu">
            <span @click="aftersalesClick(0)" :class="{shiwuActive:aftersalesTYPE==0}"></span>
            支持售后
          </div>
          <div class="feishiwu">
            <span @click="aftersalesClick(1)" :class="{shiwuActive:aftersalesTYPE==1}"></span>
            不支持
          </div>
        </li>
      </ul>
      <div class="yulan" @click="zhanshiHref" v-show="false">线上商品预览效果</div>
      <a class="fabu" @click="postprod">提交</a>
      <!-- <a  class="backTo" onclick="javascript:history.back(-1);">返回</a> -->
    </div>
    <div class="product-type-hide" :class="{producttypeon: showcates}">
      <!-- <div class="top-box">
        选择分类
    </div>
    <ul>
      <li class="fenleiLi" @click="selcate(item.id,item.name)" v-for="(item,ind) in selfcats" :class="{active: custom_type_id== item.id}" :key="item.ind">{{item.name}}</li>
      </ul>-->

      <div style="width:100%; height:100%; background: #F2F2F2;;">
        <div class="home">
          <div class="solid">
            <ul>
              <li
                @click="show(item.id)"
                v-for="item in toplist"
                :key="item.id"
                :class="{newisfor:cateid==item.id}"
              >
                <span>{{item.name}}</span>
              </li>
            </ul>
          </div>

          <div class="boxcen">
            <ul>
              <li
                v-for="ins in boxlist"
                :key="ins.id"
                @click="bomshow(ins.id)"
                :class="{she:claid==ins.id}"
              >
                <span>{{ins.name}}</span>
              </li>
            </ul>
          </div>

          <div class="bombox" style="padding-right:40px;">
            <ul>
              <li
                v-for="end in bomlist"
                :key="end.id"
                @click="bomstall(end.id,end.name)"
                :class="{bomcas:bomid==end.id}"
              >
                <span>{{end.name}}</span>
              </li>
            </ul>
          </div>
        </div>
        <div
          class="bomtext"
        >&nbsp;&nbsp;&nbsp;&nbsp;亲,根据平台管控及行业的要求,部分类目不支持无线发布。若没有找到正确的类目,请到网页端卖家中心进行商品发布。</div>
      </div>

      <a @click="showcates=false" class="backTo backTo1">返回</a>
    </div>
    <div v-show="fengmian_sh" class="fengmian_show">
      <!--v-show="fengmian_sh"-->
      <div class="fengmian_show_header">
        <h1>设置产品封面</h1>
        <ul>
          <li v-for="(iu, index) in imgUrls" :key="iu.index">
            <img :src="iu" :class="{border_img:fengmian_index==index}" @click="Thecover(index,iu)">
          </li>
        </ul>
        <div class="clearfix"></div>
        <div class="btn_new">
          <button @click="fengmian_show">取消</button>
          <button @click="Thecover_sub">确定</button>
        </div>
      </div>
    </div>
    <mt-datetime-picker ref="picker" type="date" v-model="dataTimeq" @confirm="handleConfirm"></mt-datetime-picker>
    <mt-datetime-picker ref="picker1" type="date" v-model="dataTimeq1" @confirm="handleConfirm1"></mt-datetime-picker>
  </div>
</template>
<style scoped>
@import "../../../assets/business/css/release_product.css";
.fenleiLi {
  line-height: 40px;
  border-bottom: 1px solid #e5e5e5;
}
.product-type-hide {
  overflow: scroll;
}
.yulan {
  color: #6eacfc;
  text-align: right;
  margin: 8px;
  text-decoration: underline;
}
.fabu {
  margin-bottom: 50px;
}
.textlistLi {
  width: 90%;
  margin-top: 5%;
  background: #f7f7f7;
  border: 0;
}
.shiwu span,
.feishiwu span {
  width: 22px;
  height: 22px;
  display: block;
  float: left;
  vertical-align: middle;
  margin-right: 8px;
  background: url("../../../assets/personal/images/bsgg.png") no-repeat;
  background-size: 100% 100%;
  margin-top: 10px;
}
.shiwuActive {
  width: 22px;
  height: 22px;
  display: block;
  float: left;
  vertical-align: middle;
  margin-right: 8px;
  background: url("../../../assets/personal/images/choose-icon-active.png")
    no-repeat !important;
  background-size: 100% 100% !important;
  margin-top: 10px;
}
.shiwu {
  margin-right: 20px;
}
.feishiwu {
  margin-right: 20px;
}
.list-img-close {
  background: red;
  height: 15px;
  width: 15px;
  position: absolute;
  top: 0px;
  right: 0px;
  background: url("../../../assets/personal/images/addcha.png") no-repeat;
  background-size: 100% 100%;
}
.border_img {
  border: 1px solid red;
}
.btn_new button {
  width: 50%;
  height: 42px;
}
.clearfix {
  clear: both;
}
.jinqian {
  margin-left: 6rem;
}
input {
  border: none;
}
.release-list .list-li .rt-input {
  border: none;
}
.fengmian {
  width: 40px;
  height: 30px;
  vertical-align: middle;
}
.fengmian_show {
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  position: fixed;
  top: 0;
}
.fengmian_show_header {
  width: 80%;
  /*  height: 167px;*/
  background: #ffffff;
  margin: 0 auto;
  margin-top: 171px;
  border-radius: 5px;
}
.fengmian_show_header h1 {
  font: 17px 宋体;
  border-bottom: 1px solid #e5e5e5;
  line-height: 50px;
}
.fengmian_show_header li {
  margin: 20px 7px;
  float: left;
}
.fengmian_show_header li img {
  width: 60px;
  height: 60px;
}
</style>
<script>
import moment from "moment";
export default {
  data: function() {
    return {
      imgUrls: [],
      imgUrlsxp: [],
      selfcats: [],
      goodsName: "",
      custom_type_id: 0,
      goodsScreenPrice: "",
      catname: "商家自定义",
      showcates: false,
      cmid: "",
      fengmian_sh: false,
      fengmian_index: 0,
      iu_url:
        "",
      ChooseStyle: 0,
      wenzishuoming: "",
      tupxuanzeType: "",
      szstype: "", //判断用
      aftersalesTYPE: 0,
      logisticsStype: 1,
      dataTimeq: new Date(), //moment(new Date()).format('YYYY-MM-DD')//,
      dataTimeq1: new Date(),
      dataTimeqishi: "",
      dataTimejieshu: "",
      goodsID: this.$route.query.good,
      albumsUrl: [], //头图，
      detailsAlbumsUrl: [], //底图,
      toplist: [],
      cateid: "",
      level: 1,
      claid: 1,
      boxlist: [],
      bomlist: [],
      bomid: 1
    };
  },

  methods: {
    show(ind) {
      this.cateid = ind;

      this.$http
        .get(this.APIURL_PREFIX + "/api/wap/categorys", {
          params: { level: this.level + 1, parentId: ind }
        })
        .then(response => {
          this.boxlist = response.data.data;
          console.log(this.boxlist);
        });
    },
    bomshow(id) {
      this.claid = id;
      this.bomins = true;
      this.$http
        .get(this.APIURL_PREFIX + "/api/wap/categorys", {
          params: { level: this.level + 2, parentId: id }
        })
        .then(response => {
          console.log(response);
          this.bomlist = response.data.data;
        });
    },
    bomstall(id, name) {
      console.log(id, name);
      this.custom_type_id = id;
      this.cateid = id;
      this.catname = name;
      this.showcates = false;
    },
    edit: function() {
      if ("undefined" != typeof this.goodsID) {
        var vm = this;
        this.$http
          .get(
            this.APIURL_PREFIX +
              "/api/goods/detailsGoods?goodsId=" +
              this.goodsID
          )
          .then(response => {
            this.ChooseStyle = response.data.goods.isMaterial;
            this.logisticsStype = response.data.goods.distributionMode;
            this.goodsName = response.data.goods.goodsName;
            this.goodsScreenPrice = response.data.goods.goodsScreenPrice / 100;
            this.wenzishuoming = response.data.goods.detaileDescription;
            this.aftersalesTYPE = response.data.goods.isAfterSale;
            this.albumsUrl = response.data.albumsUrl;
            this.iu_url = response.data.goods.goodsThum;
            this.detailsAlbumsUrl = response.data.detailsAlbumsUrl;
            this.cmid = response.data.goods.goodsProviderId;
            if ("undefined" != typeof response.data.goods.customType) {
              this.catname = response.data.goods.customType;
              this.custom_type_id = response.data.goods.customTypeId;
              this.cateid = response.data.goods.cateId;
            }
            this.ChooseStyle = response.data.goods.isMaterial;
            this.logisticsStype = response.data.goods.distributionMode;
            if ("" != response.data.goods.endDate) {
              this.dataTimeqishi = response.data.goods.startDate;
              this.dataTimejieshu = response.data.goods.endDate;
            }
            var fengmian = response.data.albumsUrl;
            var imgUrls = [];
            fengmian.forEach(element => {
              imgUrls.push(element.url);
            });
            this.imgUrls = imgUrls;
          })
          .catch(function(err) {
            console.log(err);
          });
      }
    },
    handleConfirm1(v) {
      //时间
      var nian = v.getFullYear();
      var yue = v.getMonth();
      var ri = v.getDate();
      this.dataTimejieshu = nian + "-" + (yue + 1) + "-" + ri;
    },
    handleConfirm(v) {
      //时间
      var nian = v.getFullYear();
      var yue = v.getMonth();
      var ri = v.getDate();
      this.dataTimeqishi = nian + "-" + (yue + 1) + "-" + ri;
    },
    openPicker1() {
      //时间
      this.$refs.picker1.open();
    },
    openPicker() {
      //时间
      this.$refs.picker.open();
    },
    zhanshiHref: function() {
      //展示页面
      // this.$router.push({ name: 'zhanshiImg'});   http://static.ruitaowang.com/attached/file/2018/12/18/20181218140206291.jpg
      layer.open({
        type: 1,
        title: "线上预览展示",
        scrollbar: false,
        shadeClose: true,
        shade: 0.8,
        area: ["100%", "100%"],
        content:
          "<img style='width:100%;' src='http://pjx6ntpju.bkt.clouddn.com/zhanshi.jpg'>"
      });
    },
    logistics: function(type) {
      //物流
      this.logisticsStype = type;
    },
    aftersalesClick: function(type) {
      //支不支持售后
      console.log(type);
      this.aftersalesTYPE = type;
    },
    tupxuanze: function(type, sztype) {
      //图片上传选择
      this.tupxuanzeType = type;
      this.szstype = sztype;
      console.log(this.szstype);
      console.log(this.tupxuanzeType);
    },
    ItemsChoose: function(type) {
      //选择有无实物1是非实物
      this.ChooseStyle = type;
    },
    Thecover(inde, iu) {
      this.fengmian_index = inde;
      this.iu_url = iu;
    },
    Thecover_sub() {
      this.imgUrls.splice(this.fengmian_index, 1);
      this.imgUrls.unshift(this.iu_url);
      this.fengmian_sh = !this.fengmian_sh;
      this.fengmian_index = 0;
    },
    fengmian_show: function() {
      if (0 < this.imgUrls.length) {
        this.fengmian_sh = !this.fengmian_sh;
      } else {
        layer.msg("请先上传商品图片");
      }
    },
    leimu() {
      console.log("类目");
    },
    loadcats: function() {
      this.cmid = this.$route.query.cmid;
      // this.$http.get(this.APIURL_PREFIX+'/api/wap/goodsTypeCustom/page?page=1').then((response) => {
      //   console.log(response.data)
      //   this.selfcats = response.data.data;
      // }).catch(function(err){
      //   console.log(err)
      // });

      this.$http
        .get(this.APIURL_PREFIX + "/api/wap/categorys", {
          params: { level: this.level }
        })
        .then(response => {
          console.log(response);
          this.toplist = response.data.data;
        });
    },
    selcate(id, name) {
      this.custom_type_id = id;
      this.catname = name;
      this.showcates = false;
    },
    postprod() {
      var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
      if (this.imgUrls.length == 0) {
        layer.msg("请上传图片");
        return false;
      }
      if ("" == this.goodsName) {
        layer.msg("标题不能为空");
        return;
      }
      if ("" == this.goodsScreenPrice) {
        layer.msg("价钱不能为空");
        return;
      }
      if (reg.test(this.goodsScreenPrice) && this.goodsScreenPrice <= 1000000) {
        if ("undefined" == typeof this.goodsID) {
          if (this.ChooseStyle == 0) {
            //实物
            this.$http
              .post(
                this.APIURL_PREFIX + "/api/goods",
                $.param({
                  goodsName: this.goodsName,
                  // customTypeId:this.custom_type_id,
                  cateId: this.cateid,
                  goodsScreenPrice: this.goodsScreenPrice * 100,
                  goodsProviderId: this.cmid,
                  goodsOnline: 1,
                  goodsThum: this.iu_url,
                  isMaterial: this.ChooseStyle, //是否有实物0实物1非
                  distributionMode: this.logisticsStype, //配送方式0物流1自己配送
                  detaileDescription: this.wenzishuoming, //说明
                  // detailePicture:this.imgUrlsxp,//详情图片
                  isAfterSale: this.aftersalesTYPE //是否支持售后0支持 1不支持
                })
              )
              .then(response => {
                console.log(response.data);
                if (0 == response.data.code) {
                  this.postimgprod(response.data.data.goodsId);
                } else {
                  layer.msg(response.data.msg);
                }
              })
              .catch(function(err) {
                console.log(err);
                layer.msg("添加失败");
              });
          } else if (this.ChooseStyle == 1) {
            this.$http
              .post(
                this.APIURL_PREFIX + "/api/goods",
                $.param({
                  goodsName: this.goodsName,
                  // customTypeId:this.custom_type_id,
                  cateId: this.cateid,
                  goodsScreenPrice: this.goodsScreenPrice * 100,
                  goodsProviderId: this.cmid,
                  goodsOnline: 1,
                  goodsThum: this.iu_url,
                  isMaterial: this.ChooseStyle, //是否有实物0实物1非
                  startDate: this.dataTimeqishi, //开始时间
                  endDate: this.dataTimejieshu, //结束时间
                  detaileDescription: this.wenzishuoming, //说明
                  // detailePicture:this.imgUrlsxp.join(","),//详情图片
                  isAfterSale: this.aftersalesTYPE //是否支持售后0支持 1不支持
                })
              )
              .then(response => {
                console.log(response.data);
                if (0 == response.data.code) {
                  this.postimgprod(response.data.data.goodsId);
                } else {
                  layer.msg(response.data.msg);
                }
              })
              .catch(function(err) {
                console.log(err);
                layer.msg("添加失败");
              });
          }
        } else {
          this.$http
            .put(
              this.APIURL_PREFIX + "/api/wap/goods",
              $.param({
                goodsId: this.goodsID,
                goodsName: this.goodsName,
                // customTypeId:this.custom_type_id,
                cateId: this.cateid,
                goodsScreenPrice: this.goodsScreenPrice * 100,
                goodsProviderId: this.cmid,
                goodsOnline: 1,
                goodsThum: this.iu_url,
                isMaterial: this.ChooseStyle, //是否有实物0实物1非
                distributionMode: this.logisticsStype, //配送方式0物流1自己配送
                detaileDescription: this.wenzishuoming, //说明
                startDate: this.dataTimeqishi, //开始时间
                endDate: this.dataTimejieshu, //结束时间
                // detailePicture:this.imgUrlsxp,//详情图片
                isAfterSale: this.aftersalesTYPE //是否支持售后0支持 1不支持
              })
            )
            .then(response => {
              layer.msg("修改成功");
              console.log(this.cmid);
              this.$router.push({
                name: "Business_Cp_manage",
                query: { cmid: this.cmid }
              });
            })
            .catch(function(err) {
              console.log(err);
              layer.msg("修改失败");
            });
        }
      } else {
        layer.msg("金钱格式有误");
      }
    },
    postimgprod(id) {
      var vm = this;
      this.$http
        .post(
          this.APIURL_PREFIX + "/api/wap/goodsAlbum/create",
          $.param({
            imgUrl: this.imgUrls.join(","),
            detailePictureUrl: this.imgUrlsxp.join(","),
            imageType: 1,
            goodsId: id,
            goodsProviderId: this.cmid
          })
        )
        .then(response => {
          console.log(response.data);
          if (0 == response.data.code) {
            layer.confirm(
              "添加成功，是否继续添加",
              {
                btn: ["确定", "取消"] //按钮
              },
              function() {
                layer.msg("添加成功");
                vm.$router.push({ name: "Business_release_product" });
              }
            );
            // if(confirm("添加成功，是否继续添加")){
            //   this.$router.push({ name: 'Business_release_product'})
            // }
            // else{
            this.$router.push({
              name: "Business_Cp_manage",
              query: { cmid: this.cmid }
            });
            // }
          } else {
            layer.msg("图片添加失败");
          }
        })
        .catch(function(err) {
          console.log(err);
          layer.msg("图片添加失败");
        });
    },
    onFileChange: function(e, targetparam) {
      var files = e.target.files || e.dataTransfer.files;
      console.log(targetparam);
      console.log(this[targetparam]);

      if (!files.length) return;
      this.createImage(files, e, targetparam);
    },
    createImage: function(file, e, targetparam) {
      console.log(file, e, targetparam);
      let vm = this;
      lrz(file[0], { width: 480 })
        .then(function(rst) {
          vm.$http({
            url: vm.APIURL_PREFIX + "/uploadForCertificate",
            method: "post",
            data: rst.formData
          })
            .then(response => {
              console.log(response.data.msg + "19999");
              if (0 == response.data.code) {
                if (targetparam) {
                  vm[targetparam] = response.data.msg;
                } else {
                  if (vm.tupxuanzeType == 0) {
                    if (vm.szstype == 0) {
                      if (vm.imgUrls.length) {
                        vm.imgUrls.push(response.data.msg);
                      } else {
                        vm.imgUrls = [response.data.msg];
                      }
                    } else {
                      vm.$http
                        .post(
                          vm.APIURL_PREFIX + "/api/goods/updateImage",
                          $.param({
                            url: response.data.msg,
                            imageType: 1,
                            goodsId: vm.goodsID
                          })
                        )
                        .then(response => {
                          vm.edit();
                        })
                        .catch(function(err) {
                          console.log(err);
                          layer.msg("添加失败");
                        });
                    }
                  } else if (vm.tupxuanzeType == 1) {
                    if (vm.szstype == 0) {
                      if (vm.imgUrlsxp.length) {
                        vm.imgUrlsxp.push(response.data.msg);
                        console.log(vm.imgUrlsxp);
                      } else {
                        vm.imgUrlsxp = [response.data.msg];
                      }
                    } else {
                      vm.$http
                        .post(
                          vm.APIURL_PREFIX + "/api/goods/updateImage",
                          $.param({
                            url: response.data.msg,
                            imageType: 2,
                            goodsId: vm.goodsID
                          })
                        )
                        .then(response => {
                          vm.edit();
                        })
                        .catch(function(err) {
                          console.log(err);
                          layer.msg("添加失败");
                        });
                    }
                  }
                }
              }
            })
            .catch(function(err) {
              layer.msg("上传失败");
              console.log(err);
            });
          return rst;
        })
        .always(function() {
          e.target.value = null;
        });
    },
    delImage: function(index) {
      let vm = this;
      if (confirm("确定删除该图片？")) {
        vm.imgUrls.splice(index, 1);
      }
    },
    delImagegod: function(id) {
      if (confirm("确定删除该图片？")) {
        this.$http
          .delete(this.APIURL_PREFIX + "/api/wap/goodsAlbum/" + id)
          .then(response => {
            this.edit();
          })
          .catch(function(err) {});
      }
    },
    delImagetp: function(index) {
      let vm = this;
      if (confirm("确定删除该图片？")) {
        vm.imgUrlsxp.splice(index, 1);
      }
    }
  },
  watch: {
    imgUrls: function(newVal, oldVal) {
      if (newVal.length) {
        this.iu_url = newVal[0];
      } else {
        this.iu_url =
          "";
      }
    },
    wenzishuoming: function(newVal, oldVal) {
      if (newVal.length > 200) {
        this.wenzishuoming = oldVal;
      }
    }
  },
  mounted() {
    // console.log(moment)
    // console.log( (new Date()).getFullYear()+"-"+(new Date()).getMonth()+"-"+(new Date()).getDate())
    var date = new Date();
    var nian = date.getFullYear().toString();
    var yue = date.getMonth();
    var ri = date.getDate().toString();
    console.log(nian + "-" + (yue + 1) + "-" + ri);
    this.dataTimeqishi = nian + "-" + (yue + 1) + "-" + ri;
    // this.dataTimeq = (new Date()).getFullYear()+"-"+(new Date()).getMonth()+"-"+(new Date()).getDate()
    this.loadcats();
    this.edit();
    this.show();
    this.bomshow();
  }
  //      // console.log(response.data.goods.isMaterial)
  // console.log(response.data.goods.distributionMode)
  // console.log(response.data.goods.goodsName)
  // console.log(this.aftersales)
  //  this.imgUrlsxp=response.data.detailsAlbumsUrl
  //  console.log(this.imgUrlsxp)
  // console.log(this.ChooseStyle)
  // console.log(this.logisticsStype)
  // console.log(this.goodsName)
  // console.log( this.goodsScreenPrice)
  // console.log(this.wenzishuoming)
};
</script>
